package com.example.mychat.controller;

import com.example.mychat.annotation.GlobalInteceptor;
import com.example.mychat.entity.dto.SysSettingDto;
import com.example.mychat.entity.po.AppUpdate;
import com.example.mychat.entity.query.AppUpdateQuery;
import com.example.mychat.entity.vo.PaginationResultVO;
import com.example.mychat.entity.vo.ResponseVO;
import com.example.mychat.service.AppUpdateService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.IOException;

/**
 * @Description
 * @Author susu
 * @Date 2024/9/9
 */
@RestController
@RequestMapping("/admin")
public class AppUpdateController extends ABaseController{

    @Resource
    private AppUpdateService appUpdateService;

    @RequestMapping("/loadUpdateList")
    @GlobalInteceptor(checkAdmin = true)
    public ResponseVO loadUpdateList(AppUpdateQuery query){
        query.setOrderBy("create_time desc");
        PaginationResultVO<AppUpdate> listByPage = appUpdateService.findListByPage(query);

        return getSuccessResponseVO(listByPage);

    }

    @RequestMapping("/saveUpdate")
    @GlobalInteceptor(checkAdmin = true)
    public ResponseVO saveUpdate(Integer id,
                                 @NotEmpty String version,
                                 @NotEmpty String updateDesc,
                                 @NotNull Integer fileType,
                                  String outerLink,
                                 MultipartFile file) throws IOException {
        AppUpdate update = new AppUpdate();
        update.setId(id);
        update.setVersion(version);
        update.setUpdateDesc(updateDesc);
        update.setFileType(fileType);
        update.setOuterLink(outerLink);

        appUpdateService.saveUpdate(update,file);
        return getSuccessResponseVO(null);

    }


    @RequestMapping("/delUpdate")
    @GlobalInteceptor(checkAdmin = true)
    public ResponseVO delUpdate(Integer id){
        appUpdateService.deleteAppUpdateById(id);
        return getSuccessResponseVO(null);
    }

    @RequestMapping("/postUpdate")
    @GlobalInteceptor(checkAdmin = true)
    public ResponseVO postUpdate(Integer id,Integer status,String grayscaleUid){
        appUpdateService.postUpdate(id,status,grayscaleUid);
        return getSuccessResponseVO(null);
    }


}
